ccR.Sys = {
	Default = function()
		-- Main Default's for ccR
				ccR.Default("Rotation", "Empty")
				ccR.Default("MinimapPos", 90)
				ccR.Default("Dancing_CactuaR", true)
				ccR.Default("Toggle", false)
			-- AoE
				ccR.Default("AutoAoE", true)
				ccR.Default("SingleTarget", true) 
				ccR.Default("SingleTargetCount", 1)
				ccR.Default("AoE", true)
				ccR.Default("AoECount", 2)
				ccR.Default("ManualAoE", false)
			-- GUI
				-- Racials
					ccR.Default("Use_Blood_Fury",true)
					ccR.Default("Use_Berserking",true)
					ccR.Default("Use_OnBossOnly",false)
					ccR.Default("Use_Arcane_Torrent",true)
					ccR.Default("Arcane_Torrent_Count", 3)
					ccR.Default("Use_Warstomp",true)
					ccR.Default("Warstomp_Count", 3)
					ccR.Default("Use_Quaking_Palm",true)
					ccR.Default("Use_Gift_of_the_Naaru",true)
					ccR.Default("Gift_of_the_Naaru_Count", 80)
					ccR.Default("Use_Stoneform",true)
					ccR.Default("Use_Escape_Artist",true)
					ccR.Default("Use_Every_man_for_Himself",true)
					ccR.Default("Use_Will_of_the_Forsaken",true)
				-- Trinkets
					ccR.Default("Trinket_13", true)
					ccR.Default("Trinket_13_OnlyOnBoss", false)
					ccR.Default("Trinket_14", true)
					ccR.Default("Trinket_14_OnlyOnBoss", false)
				-- Options
					-- Run rotation on mount
						ccR.Default("Use_Rotation_On_Mount", true)
					-- Hide Toggle
						ccR.Default("Hide_Toggle", false)
				-- Auto
					-- Auto Face
						ccR.Default("Use_Auto_Face", true)
						ccR.Default("Auto_Face_Delay", 0.25)
						ccR.Default("Auto_Face_InCombatOnly", true)
					-- Auto Loot
						ccR.Default("Use_Auto_Loot", true)
						ccR.Default("Auto_Loot_Use_LootARang", true)
						ccR.Default("Auto_Loot_Use_Fetch", true)
						ccR.Default("Auto_Loot_In_Stealth", false)
						ccR.Default("Auto_Loot_In_Dungeons", true)
					-- Auto Target
						ccR.Default("Use_Auto_Target", true)
						ccR.Default("Auto_Target_Ignore_Pets", true)
						ccR.Default("Auto_Target_Delay", 0.25)
						ccR.Default("Auto_Target_Style", "InGroup")
							ccR.Default("Auto_Target_In_Group", true)
							ccR.Default("Auto_Target_Tapped_Only", false)
							ccR.Default("Auto_Target_Lowest_Health", false)
							ccR.Default("Auto_Target_Closest", true)
						ccR.Default("Auto_Target_Ignore_Tapped", true)
					-- Auto Skin
						ccR.Default("Use_Auto_Skin", true)
					-- Health Potions
						ccR.Default("Use_Health_Potions", true)
						ccR.Default("Health_Potion_HP", 35)
					-- Mana Potions
						ccR.Default("Use_Mana_Potions", true)
						ccR.Default("Mana_Potion_MP", 35)
					-- Auto Open
						ccR.Default("Use_Auto_Open", true)
					-- Auto Loot
						ccR.Default("Use_Auto_Loot", true)
					-- Auto Join LFG
						ccR.Default("Use_Auto_LFG", true)
						ccR.Default("Auto_LFG_Time", 5)
						ccR.Default("Auto_LFG_NotInCombat", true)
					-- Auto Join PVP
						ccR.Default("Use_Auto_PVP", true)
						ccR.Default("Auto_PVP_Time", 5)
						ccR.Default("Auto_PVP_NotInCombat", true)
				-- Debug
					ccR.Default("Debug", false)
					ccR.Default("Debug_Delay", 0.25)
				-- Advanced
					ccR.Default("LoS_AutoTarget", true)
					ccR.Default("LoS_WorldToScreen", true)
					ccR.Default("LoS_SpellCanAttack", true)
					ccR.Default("LoS_CastAttack", true)
					ccR.Default("WTS_AutoTarget", true)
					ccR.Default("UseObjectList", true)
					ccR.Default("Object_List_Delay", 0.25)
					ccR.Default("Object_List_Partial", false)
					ccR.Default("UseRotation", true)
					ccR.Default("Rotation_Speed", 0.25)
					ccR.Default("UseClassFeatures", true)
					ccR.Default("Player_Features_Delay", 0.50)
			-- Reset
			ccR.Var("Auto_Target_Pause", false)
			ccR.Var("Auto_Loot_Pause", false)
			-- Class Features
				-- Death Knight
					ccR.Default("Deaths_Advance", true)
					ccR.Default("Deaths_Advance_Time", 2)
				-- Rogue
					ccR.Default("Auto_Stealth", true)
						ccR.Default("Auto_Stealth_Resting", true)
					ccR.Default("Auto_Burst_of_Speed", true)
						ccR.Default("Burst_of_Speed_Energy", 80)
						ccR.Default("ABOS_InStealth", true)
						ccR.Default("ABOS_OutOfStealth", true)
					ccR.Default("Auto_Recuperate", true)
						ccR.Default("Recuperate_HP", 95)
						ccR.Default("AR_InCombat", true) 
						ccR.Default("AR_OutOfCombat", true)
					ccR.Default("Auto_TricksoftheTrade", true)
				-- Monk
					ccR.Default("Nimble_Brew", true)
				-- Priest
					ccR.Default("Angelic_Feather", true)
					ccR.Default("Angelic_Feather_Time", 2)
				-- Hunter
					ccR.Default("Aspect_of_the_Cheetah", true)
				-- Mage
					ccR.Default("Slow_Fall", true)
					ccR.Default("Slow_Fall_Time", 1)
	end,
	Copy_Default_Settings =
	function(src, dst)
		if type(src) ~= "table" then return {} end
		if type(dst) ~= "table" then dst = {} end
		for k, v in pairs(src) do
			if type(v) == "table" then
				dst[k] = ccR.Sys.Copy_Default_Settings(v, dst[k])
			elseif type(v) ~= type(dst[k]) then
				dst[k] = v
			end
		end
		return dst
	end,
	CactuaR = {
		Animation = function(self, elapsed)
		    if not ccR.Var("Toggle") then
		        ccR.Sys.CactuaR.Toggle("off") 
		        frCactuaR:Hide()
		        imgCactuaR:Hide()
		        return
		    end
		    if not frCactuaR:IsVisible() then frCactuaR:Show() end
		    if not imgCactuaR:IsVisible() then imgCactuaR:Show() end
		    AnimateTexCoords(imgCactuaR, 128, 64, 64, 64, 2, elapsed, 0.1)
		end,
		Load =
		function()
		    if not frCactuaR then
		        frCactuaR = CreateFrame("Frame", "CactuaR", UIParent)
		        frCactuaR:SetFrameStrata("DIALOG")
		        frCactuaR:SetWidth("64")
		        frCactuaR:SetHeight("64")
		        if CactuaRX and CactuaRY then
		            frCactuaR:ClearAllPoints()
		            frCactuaR:SetPoint("BOTTOMLEFT", "UIParent", "BOTTOMLEFT", CactuaRX, CactuaRY)
		        else
		            frCactuaR:ClearAllPoints()
		            frCactuaR:SetPoint("CENTER")
		        end
		        imgCactuaR = frCactuaR:CreateTexture("imgCactuaR")
		        imgCactuaR:SetTexture("Interface\\Addons\\_ccR\\_SYS\\Img\\Cactuar.tga")
		        imgCactuaR:SetAllPoints(frCactuaR)
		        frCactuaR:SetMovable(true)
		        frCactuaR:EnableMouse(true)
		        frCactuaR:RegisterForDrag("LeftButton")
		        frCactuaR:SetScript("OnDragStart", frCactuaR.StartMoving)
		        frCactuaR:SetScript("OnDragStop", function(self) CactuaRX, CactuaRY = self:GetRect(); frCactuaR:StopMovingOrSizing() end)
		        frCactuaR:SetUserPlaced(enable)
		        frCactuaR:Hide()
		    end
		end,
		Toggle =
		function(var)
	        if var == "off" then
	            frCactuaR:SetScript("OnUpdate", nil)
	            frCactuaR:Hide()
	            imgCactuaR:Hide()
	        end
	        if var == "on" then
	            frCactuaR:SetScript("OnUpdate", ccR.Sys.CactuaR.Animation)
	            frCactuaR:Show()
	            imgCactuaR:Show()
	        end
		end,
	},
	Error = function(msg) local vMsg = "|cff00ff00ccR /> [|cFFC00000Error|r|cff00ff00] " DEFAULT_CHAT_FRAME:AddMessage(vMsg .. string.join(" ", tostringall(msg)), 0.41, 0.8, 0.94) end,
	FireHack = function()
		if FireHack then
			return true
		else
			ccR.Sys.Error("FireHack not found.")
			return false
		end
	end,
	Valid = function(rotation)
		if ccR.Boss[rotation] ~= nil then
			if tContains(ccR.Boss[rotation], ccR.Player.Name()) then
				return true
			else
				ccR.PrintToChat(ccR.Player.Name() .. " is NOT registered for " .. rotation)
				return false
			end
		else
			return true
		end
	end,
	IgnoreNPCWithAura =
	function(unit)
		if unit == nil then unit = "target" end
		if ccR.Unit.Exists(unit) then
			local unitid = ccR.Unit.NPCID(unit)
			-- /dump ccR.tblIgnoreNPCCastingSpell[ccR.Unit.NPCID("target")]
			-- /dump ccR.Unit.Is.CastingSpell(unit, ccR.tblIgnoreNPCCastingSpell[ccR.Unit.NPCID("target")])
			-- /dump ccR.Unit.Is.ChannelingSpell(unit, ccR.tblIgnoreNPCCastingSpell[ccR.Unit.NPCID("target")])
			if ccR.Unit.Is.CastingOrChanneling(unit) then
				if ccR.tblIgnoreNPCCastingSpell[unitid] ~= nil then
					local vSpell = ccR.tblIgnoreNPCCastingSpell[unitid]
					if 
					(
						ccR.Unit.Is.CastingSpell(unit, vSpell)
						or 
						ccR.Unit.Is.ChannelingSpell(unit, vSpell)
					) 
					then 
						return true
					end
				end
			end
			-- /dump ccR.tblIgnoreNPCWithAura[ccR.Unit.NPCID("target")]
			-- /dump ccR.Unit.Has.Aura("target", ccR.tblIgnoreNPCWithAura[ccR.Unit.NPCID("target")])
			if ccR.tblIgnoreNPCWithAura[unitid] ~= nil then 
				local vAura = ccR.tblIgnoreNPCWithAura[unitid]
				if type(vAura) == "number" then	if (ccR.Unit.Has.Buff(unit, vAura) or ccR.Unit.Has.Debuff(unit, vAura) or ccR.Unit.Has.Aura(unit, vAura)) then return true end end
				if type(vAura) == "table" then
					for x = 1, #vAura do
						if (
								--ccR.Unit.Has.Buff(unit, vAura[x]) 
								--or ccR.Unit.Has.Debuff(unit, vAura[x]) 
								ccR.Unit.Has.Aura(unit, vAura[x])
							) 
						then 
							return true 
						end
					end
				end
			end
			return false
		end
	end,
	Load = {
		Initialize = 
		function()
			ccR.Sys.Default()
			ccR.Sys.Load.ClassFolder()
			ccR.GUI.Update()
		end,
		ClassFolder =
		function()
			if FireHack then
				local vName, vClass, vID = UnitClass("player") 
				local FolderClass
				if vID == 1 then FolderClass = "Warrior" 
				elseif vID == 2 then FolderClass = "Paladin" 
				elseif vID == 3 then FolderClass = "Hunter" 
				elseif vID == 4 then FolderClass = "Rogue" 
				elseif vID == 5 then FolderClass = "Priest" 
				elseif vID == 6 then FolderClass = "Death Knight" 
				elseif vID == 7 then FolderClass = "Shaman" 
				elseif vID == 8 then FolderClass = "Mage" 
				elseif vID == 9 then FolderClass = "Warlock" 
				elseif vID == 10 then FolderClass = "Monk" 
				elseif vID == 11 then FolderClass = "Druid"
				end
				ccR.table_empty(ccR.Rotations)
				local Folder = GetWoWDirectory() .. "\\Interface\\AddOns\\_ccR\\Rotations\\"
				for Key, Directory in pairs(GetSubdirectories(Folder .. "*")) do
					if Directory ~= nil
					and UnitClass("player") ~= nil
					then
						ccR.Sys.Load.Folder(Folder .. Directory .. "\\" .. FolderClass  .. "\\")
					end
				end
			end
		end,
		Folder =
		function(Folder)
			for Key, File in pairs(GetDirectoryFiles(Folder .. "\\*")) do
				if ReadFile(Folder .. "\\" .. File) ~= nil then
					loadstring(ReadFile(Folder .. "\\" .. File))();
				end
			end
			for Key, Directory in pairs(GetSubdirectories(Folder .. "\\*")) do
				ccR.Sys.Load.Folder(Folder .. "\\" .. Directory);
			end
		end,
	},
	PrintToChat = function(msg)	local vLogo = "|cff00ff00ccR /> " DEFAULT_CHAT_FRAME:AddMessage(vLogo .. string.join(" ", tostringall(msg)), 0.41, 0.8, 0.94) end,
	JoinLFG = 
	function()
		if ccR.Var("Auto_LFG_NotInCombat") then
			if not ccR.Player.Is.In.Combat() and not ccR.Player.Is.In.Raid() then
				AcceptProposal()
				ccR_Timer.Unregister('AutoJoinLFG')
			end
		else
			AcceptProposal()
			ccR_Timer.Unregister('AutoJoinLFG')
		end
	end,
	JoinPVP = 
	function()
		if ccR.Var("Auto_PVP_NotInCombat") then
			if not ccR.Player.Is.In.Combat() then
				if GetMaxBattlefieldID() > 0 then
					for i=1, GetMaxBattlefieldID() do
						status, mapName, instanceID = GetBattlefieldStatus(i)
						if status == "confirm" then
							AcceptBattlefieldPort(i,1)
							StaticPopup_Hide("CONFIRM_BATTLEFIELD_ENTRY")
						end
					end
				end
				ccR_Timer.Unregister('AutoJoinPVP')
			end
		else
			if GetMaxBattlefieldID() > 0 then
				for i=1, GetMaxBattlefieldID() do
					status, mapName, instanceID = GetBattlefieldStatus(i)
					if status == "confirm" then
						AcceptBattlefieldPort(i,1)
						StaticPopup_Hide("CONFIRM_BATTLEFIELD_ENTRY")
					end
				end
			end
			ccR_Timer.Unregister('AutoJoinPVP')
		end
	end,
}
setmetatable(ccR.Sys, ccR)